package com.tyros.common.exception;

import com.tyros.common.constant.BaseCode;
import com.tyros.common.constant.BaseMessage;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

/**
 * 公共异常类
 *
 * @author zhangshuaiyin
 * @date 2021/5/31 21:58
 */
@Getter
@NoArgsConstructor
@AllArgsConstructor
public class BaseException extends RuntimeException implements BaseCode {
    /**
     * 异常码
     */
    private String code;

    /**
     * 异常信息
     */
    private String message;

    public BaseException(BaseCode baseCode) {
        this.code = baseCode.getCode();
        this.message = baseCode.getMessage();
    }

    public static void throwExp(BaseCode baseCode) {
        throw new BaseException(baseCode);
    }
    
    public static void throwExp(String code) {
        throw new BaseException(BaseMessage.of(code));
    }
}
